package com.elitesland.security.handle;

import com.elitesland.core.base.ApiCode;
import com.elitesland.core.base.ApiResult;
import com.elitesland.core.util.HttpServletResponseUtil;
import lombok.SneakyThrows;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * <pre>
 * [功能说明]
 * </pre>
 *
 * @author Mir
 * @date 2020/6/25
 */
public class SimpleAccessDeniedException implements AccessDeniedHandler {
    @SneakyThrows
    @Override
    public void handle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AccessDeniedException e) throws IOException, ServletException {
        HttpServletResponseUtil.printJSON(httpServletResponse, ApiResult.fail(ApiCode.VERIFICATION_CODE_EXCEPTION, e.getMessage()));
    }
}
